#ifndef __BLK_H__
#define __BLK_H__

#include "shyper_service.h"

#define VIRTIO_BLK_T_IN 0
#define VIRTIO_BLK_T_OUT 1
#define VIRTIO_BLK_T_FLUSH 4
#define VIRTIO_BLK_T_GET_ID 8
#define VIRTIO_BLK_T_DISCARD 11
#define VIRTIO_BLK_T_WRITE_ZEROES 13

struct mediated_cache {
    u32 dev_idx;
    u64 cache_pa;
    u64 cache_ipa;
    u64 cache_kva;
    u64 cache_size;
};
struct mediated_blk_cfg {
    char name[32];
    char block_dev_path[32];
    u64 block_num;
    u64 dma_block_max;
    u64 cache_size;
    u16 idx;
    bool pcache; // TODO: enable page cache
    u64 cache_va;
    u64 cache_ipa;
    u64 cache_pa;
};

struct mediated_blk_req {
    u32 type;
    u64 sector;
    u64 count;
};

struct mediated_blk {
    u64 nreq;
    struct mediated_blk_cfg cfg;
    struct mediated_blk_req req;
} __attribute__((__aligned__(PAGE_SIZE)));

bool mediated_blk_append(u64 cfg_user_addr);
bool mediated_blk_notify(u16 blk_id);
int mediated_blk_daemon_send_req(void);

#endif